package uk.ac.nott.cs.g53dia;
/**
 * Action to deposit food in a nest.
 *
 * @author Neil Madden.
 */

/*
 * Copyright (c) 2005 Neil Madden (nem@cs.nott.ac.uk).
 * 
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

public class DepositNectarAction implements Action {
    /**
     * How much to deposit.
     */
    private int amount;

    public DepositNectarAction(int amount) {
        this.amount = amount;
    }

    public void execute(Environment env, Bee bee)
        throws ActionFailedException
    {
        if (amount < 0) {
            throw new ActionFailedException("DepositNectar: negative amount!");
        }
        if (bee.energy < amount) {
            throw new ActionFailedException("DepositNectar: not enough energy");
        }
        Cell c = env.getCell(bee.getPosition());
        if (c instanceof Nest) {
            ((Nest)c).addEnergy(amount);
            bee.useEnergy(amount);
        } else {
            throw new ActionFailedException("DepositNectar: not at nest");
        }
    }

    public String toString() {
        return "Deposit nectar";
    }
}
